package com.xs.mongo.spring.xml;

import java.util.List;

import org.bson.Document;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class Main {
	public static void main(String[] args) {
		ApplicationContext app = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
		MongoTemplate mongoTemplate = (MongoTemplate) app.getBean("mongoTemplate");

		for (int i = 0; i < 10; i++) {

			User user = new User();
			user.setUserName("zhangsna");
			user.setAge(30 + i);
			mongoTemplate.insert(user);
		}

		Query query = new Query();
		query.addCriteria(Criteria.where("age").gt(30));
		List<User> userList = mongoTemplate.find(query, User.class);

		userList.stream().forEach(e -> {
			System.out.println(e);
		});

	}
}
